<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form id="form">
        <input type="text" name="username">
        <input type="text" name="password">
        <input type="button" id="btn" value="提交">
    </form>
    <script>
        var btn = document.getElementById('btn');
        var form = document.getElementById('form');
        btn.onclick = function(){
            var formData = new FormData(form);
            var xhr = new XMLHttpRequest();

            console.log(formData.get('username'));
            formData.set('username','itcast');
            formData.append('username','itlz');
            formData.delete('password');

            xhr.open('post','http://localhost:3000/formData');
            xhr.send(formData);
            xhr.onload = function(){
                if(xhr.status == 200){
                    console.log(xhr.responseText);
                }
            }

            var f = new FormData();
            f.append('sex','男');
            console.log(f.get('sex'));
        }
    </script>
</body>
</html>